//209.长度最小的子数组
class Solution1 {
    //时间复杂度 O(N)  空间复杂度O(1)
    public int minSubArrayLen(int target, int[] nums) {
        int left = 0;
        int right = 0;
        int n = nums.length;
        int sum = 0;
        int len = Integer.MAX_VALUE;
        for(right = 0;right < n;right++){
            //进窗口
            sum += nums[right]; 
            //判断
            while(sum >= target){
                //更新结果
                len = Math.min(len,right - left + 1);
                //出窗口
                sum -= nums[left++];
            }
        }
        return len == Integer.MAX_VALUE ? 0 : len;
        
        
    }
}